
from collections import deque
import threading


class BlockingQueue(object):

    def __init__(self, max_limit=5):
        """
        :param max_limit:
        """
        self.max_limit = max_limit
        self.queue = deque()
        self.lock = threading.Lock()

    def enqueue(self, item):
        """
        :param item:
        :return:
        """
        self.queue.append(item)
        if (self.lock.locked()):
            self.lock.release()

    def dequeue(self):
        """
        :return:
        """
        if (self.queue.count() > 0) {
            return self.queue.popleft()
        } else {
            while (self.queue.count() == 0):
                self.lock.acquire(blocking=True)
            return self.queue.popleft();
        }

    def get_size(self):
        return len(self.queue)
    
    def has_data(self):
        return len(self.queue) > 0